<?php
class Model_AuthCode
{
    public static function show()
    {
        Header("Content-type: image/gif");
        $code = '';
        $width = 75;
        $height = 30;
        srand((double)microtime()*1000000); 
        $im = ImageCreate($width, $height);
        $bgcolor = ImageColorAllocate($im, 200, 233, 252);
        ImageFill($im, 0, 0, $bgcolor);
        $textColor = ImageColorAllocate($im, 0,0,0);
        for($i=0; $i<6; $i++){
            $num = mt_rand(0, 9);
            $code .= $num;
            ImageChar($im, 5, $i*10+8, 7, $num, $textColor);
        }
        Imagegif($im);
        ImageDestroy($im);
        Eren_Registry::get('SESSION')->set('code', $code);
    }
    
    public static function verify($uCode)
    {
        $code = Eren_Registry::get('SESSION')->get('code');
        Eren_Registry::get('SESSION')->set('code', '');
        if($code == '' || $uCode != $code){
            return FALSE;
        }
        return TRUE;
    }
}
